package com.lucien.Sort;
/**
 * 选择排序
 */

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

public class SelectSort {
    public static void main(String[] args) {
        int[] arr = {101, 34, 119, 1};
        selectSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void selectSort(int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            int minarr = arr[i];
            int minindex = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (minarr > arr[j]) {
                    minarr = arr[j];
                    minindex = j;
                }
            }
            if (minindex != i) {
                arr[minindex] = arr[i];
                arr[i] = minarr;
            }
        }
    }

    public static void testTime() {
        int[] arr = new int[80000];
        for (int i = 0; i < 80000; i++) {
            arr[i] = (int) (Math.random() * 80000);
        }
        Date date1 = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str1 = simpleDateFormat.format(date1);
        System.out.println("排序前的时间是：" + date1);

        selectSort(arr);

        Date date2 = new Date();
        String str2 = simpleDateFormat.format(date2);
        System.out.println("排序后的时间是：" + date2);

    }
}
